//
//  main.m
//  StrToDic
//
//  Created by 준기 반 on 11. 5. 26..
//  Copyright 2011 한성대학교. All rights reserved.
//



//
//
//
//  NSDictionary형태로 리턴하는방법을 모르겠..
//	
//
//

#import <Foundation/Foundation.h>
NSDictionary* HeartSTD(NSString *string){  //하트콘  
	
	NSArray *arr;
	NSMutableDictionary *dic=[NSMutableDictionary dictionary];
	NSArray *title=[NSArray arrayWithObjects:@"이름",@"쿠폰",@"갯수",@"기간",@"위치",@"그외",nil];
	arr=[string componentsSeparatedByString:@"♡"];
	[dic setValue:[arr objectAtIndex:0] forKey:[title objectAtIndex:0]];
	[dic setValue:[arr objectAtIndex:1] forKey:[title objectAtIndex:1]];
	[dic setValue:[arr objectAtIndex:2] forKey:[title objectAtIndex:2]];
	[dic setValue:[arr objectAtIndex:3] forKey:[title objectAtIndex:3]];
	[dic setValue:[arr objectAtIndex:4] forKey:[title objectAtIndex:4]];
	[dic setValue:[arr objectAtIndex:5] forKey:[title objectAtIndex:5]];
	for(NSString *key in dic){
		NSLog(@"%@:%@",key,[dic objectForKey:key]);
	}
    return dic;
}
void TitekMonSTD(NSString *string){  //티켓몬스터
	NSString *tempstr;
	NSArray *arr;
	NSMutableDictionary *dic=[NSMutableDictionary dictionary];
	NSArray *title=[NSArray arrayWithObjects:@"이름",@"쿠폰",@"갯수",@"기간",@"위치",@"그외",nil];
	arr=[string componentsSeparatedByString:@":"];
	NSArray *temparr;
	temparr=[[arr objectAtIndex:0] componentsSeparatedByString:@"유"];
	[dic setValue:[temparr objectAtIndex:0]forKey:[title objectAtIndex:0]];
	temparr=[[arr objectAtIndex:1] componentsSeparatedByString:@" "];
	[dic setValue:[temparr objectAtIndex:0]forKey:[title objectAtIndex:3]];
	temparr=[[arr objectAtIndex:2] componentsSeparatedByString:@"("];
	[dic setValue:[temparr objectAtIndex:0]forKey:[title objectAtIndex:1]];
	tempstr=[temparr objectAtIndex:1];
	temparr=[tempstr componentsSeparatedByString:@" "];
	[dic setValue:[temparr objectAtIndex:0] forKey:[title objectAtIndex:4]];
	tempstr=[temparr objectAtIndex:1];
	temparr=[tempstr componentsSeparatedByString:@")"];
	[dic setValue:[temparr objectAtIndex:0]forKey:[title objectAtIndex:5]];
	for(NSString *key in dic){
		NSLog(@"%@:%@",key,[dic objectForKey:key]);
	}
	
}
void CupangSTD(NSString *string){  //쿠팡
	int count=0;
	int i;
	NSString *tempstr;
	NSString *ttempstr;
	NSArray *arr;
	NSArray *temparr;
	NSMutableDictionary *dic=[NSMutableDictionary dictionary];
	NSArray *title=[NSArray arrayWithObjects:@"이름",@"쿠폰",@"갯수",@"기간",@"위치",@"그외",nil];
	arr=[string componentsSeparatedByString:@"]"];
	tempstr=[arr objectAtIndex:0];
	temparr=[tempstr componentsSeparatedByString:@" "];
	[dic setValue:[temparr objectAtIndex:1] forKey:[title objectAtIndex:1]];
	tempstr=[NSString stringWithFormat:@"%@]",[temparr objectAtIndex:0]];
	[dic setValue:tempstr forKey:[title objectAtIndex:0]];
	tempstr=[arr objectAtIndex:1];
	arr=[tempstr componentsSeparatedByString:@"/"];
	for(NSString *s in arr){
		count++;
	}
	NSLog(@"%d",count);
	tempstr=[NSString stringWithFormat:@"%@",[arr objectAtIndex:0]];
	for(i=1;i<count-1;i++){
		
		ttempstr=[NSString stringWithFormat:@"/%@",[arr objectAtIndex:count]];    //여기서 멈춤
		NSLog(@"aerbaerb");
	}
	[dic setValue:tempstr forKey:[title objectAtIndex:4]];
	for(NSString *key in dic){
		NSLog(@"%@:%@",key,[dic objectForKey:key]);
	}
}
void GiftiConSTD(NSString *string){  //기프티콘
	NSArray *arr;
	NSArray *temparr;
	NSString *tempstr;
	NSMutableDictionary *dic=[NSMutableDictionary dictionary];
	NSArray *title=[NSArray arrayWithObjects:@"이름",@"쿠폰",@"갯수",@"기간",@"위치",@"그외",nil];
	arr=[string componentsSeparatedByString:@" "];
	[dic setValue:[arr objectAtIndex:0] forKey:[title objectAtIndex:0]];
	tempstr=[NSString stringWithFormat:@"%@ %@",[arr objectAtIndex:1],[arr objectAtIndex:2]];
	[dic setValue:tempstr forKey:[title objectAtIndex:5]];
	temparr=[[arr objectAtIndex:3] componentsSeparatedByString:@":"];
	[dic setValue:[temparr objectAtIndex:1] forKey:[title objectAtIndex:4]];
	[dic setValue:[arr objectAtIndex:4] forKey:[title objectAtIndex:1]];
	[dic setValue:[arr objectAtIndex:5] forKey:[title objectAtIndex:3]];
	for(NSString *key in dic){
		NSLog(@"%@:%@",key,[dic objectForKey:key]);
	}
	
}
void GiftiShowSTD(NSString *string){ //기프티쇼
	NSArray *arr;
	NSMutableDictionary *dic=[NSMutableDictionary dictionary];
	NSArray *title=[NSArray arrayWithObjects:@"이름",@"쿠폰",@"갯수",@"기간",@"위치",@"그외",nil];
	arr=[string componentsSeparatedByString:@" "];
	[dic setValue:[arr objectAtIndex:0] forKey:[title objectAtIndex:0]];
	[dic setValue:[arr objectAtIndex:1] forKey:[title objectAtIndex:5]];
	[dic setValue:[arr objectAtIndex:3] forKey:[title objectAtIndex:1]];
	[dic setValue:[arr objectAtIndex:4] forKey:[title objectAtIndex:3]];
	arr=[[arr objectAtIndex:2] componentsSeparatedByString:@":"];
	[dic setValue:[arr objectAtIndex:1] forKey:[title objectAtIndex:4]];
	for(NSString *key in dic){
		NSLog(@"%@:%@",key,[dic objectForKey:key]);
	}
}

int main(int argc, char *argv[]) {
    NSString *tstr=@"[티몬/간지나라/더보이/빈티지환]유효기간:5.27.14시~8.31 티 켓:TPG007510121 ([전국]스타일의진리'간지나라/더보이/빈티지환' 장)";
	NSString *hstr=@"하트콘♡998000000000♡1개♡20100000까지♡스타벅스♡커피이름";
	NSString *cstr=@"[쿠팡 208690299088]엔제리너스/충남/충북-청주산남점/2011.06.30까지";
	NSString *gstr=@"[기프티콘] 아메리카노 Tall 교환처:스타벅스 <999000000000> ~06.2";
	NSString *gsstr=@"[기프티쇼] 제품명 교환처:GS25 <900-0000-0000> ~월/일";
	NSMutableDictionary *dict=[NSMutableDictionary dictionary];
    NSLog(@"%@",HeartSTD(hstr));
	TitekMonSTD(tstr);
	//CupangSTD(cstr);
	GiftiConSTD(gstr);
	GiftiShowSTD(gsstr);
	
}

